package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.controller.request.BikePageRequest;
import com.example.springboot.controller.request.HirePageRequest;
import com.example.springboot.entity.Hire;
import com.example.springboot.service.HireService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName:HireController
 * Package:com.example.springboot.controller
 * Description:
 *
 * @Author: Gao
 * @Create: 2023/2/7 - 16:55
 */
@RestController
@RequestMapping( "/hire")
public class HireController {
    @Autowired
    HireService hireService;

    @GetMapping("/")
    public Result list(){
        List<Hire> categories = hireService.list();
        return Result.success(categories);
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") Integer id){
        Hire hire = hireService.getById(id);
        return Result.success(hire);
    }

    @GetMapping("/page")
    public Result page(HirePageRequest pageRequest){
        Object page = hireService.page(pageRequest);
        return Result.success(page);
    }

    @PutMapping("/")
    public Result update(@RequestBody Hire hire){
        hireService.update(hire);
        return Result.success();
    }

    @PostMapping("/")
    public Result save(@RequestBody Hire hire){
        hireService.save(hire);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        hireService.deleteById(id);
        return Result.success();
    }

    @GetMapping("/lineCharts/{timeRange}")
    public Result lineCharts(@PathVariable String timeRange){
        return Result.success(hireService.getCountByTimeRange(timeRange));
    }
}
